package com.zego.wawaji.ui.center.pay.award;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zego.wawaji.R;
import com.zego.wawaji.base.module.ModuleMgr;
import com.zego.wawaji.ui.bean.user.newuser.SevenRed;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Su on 2018/3/10.
 */
public class PayAwardAdapter extends RecyclerView.Adapter<PayAwardAdapter.ViewHolder> {
    private Context context;
    private LayoutInflater mLayoutInflater;
    private List<SevenRed> list = new ArrayList<>();


    public PayAwardAdapter(Context context) {
        mLayoutInflater = LayoutInflater.from(context);
        this.context = context;
        list = ModuleMgr.getCenterMgr().getMyInfo().getRedList();
    }

    public void refresh() {
        list = ModuleMgr.getCenterMgr().getMyInfo().getRedList();
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mLayoutInflater.inflate(R.layout.pay_award_list, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        SevenRed data = list.get(position);
        holder.sign_day.setText("第" + (position + 1) + "天");

        holder.red_num.setVisibility(View.GONE);
        if (data.getRedStatus() == 1) {
            holder.red_img.setImageResource(R.drawable.red_can);
        } else if (data.getRedStatus() == 2) {
            holder.red_img.setImageResource(R.drawable.red_opened);
            holder.red_num.setText("+" + data.getWwCoinZs());
            holder.red_num.setVisibility(View.VISIBLE);
        } else {
            holder.red_img.setImageResource(R.drawable.red_cant);
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView red_img;
        private TextView sign_day, red_num;

        public ViewHolder(final View itemView) {
            super(itemView);
            red_img = (ImageView) itemView.findViewById(R.id.red_img);
            sign_day = (TextView) itemView.findViewById(R.id.sign_day);
            red_num = (TextView) itemView.findViewById(R.id.red_num);
        }
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }
}